package com.huarui.market.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.ewaf.framework.service.BaseService;

import com.huarui.company.dao.ICompanyDao;
import com.huarui.company.model.Company;
import com.huarui.market.dao.IMarketDao;
import com.huarui.market.model.Market;
import com.huarui.user.model.SessionMessage;
import com.huarui.user.security.UserHolder;

public class MarketService extends BaseService{
	private ICompanyDao companyDao;
	private IMarketDao getDao() {
		return (IMarketDao) super.dao;
	}
	
	/**
	 * 后台查询
	 * @param paramsMap
	 * @return
	 */
	public Map<String, Object> getMarketListByComplex(Map<String, Object> paramsMap) {
		Integer totalProperty = getDao().getMarketListCountByComplex(paramsMap);
		List<Map<String, Object>> list = getDao().getMarketListByComplex(paramsMap);
		paramsMap.clear();
		paramsMap.put("totalProperty", totalProperty);
		paramsMap.put("root", list);
		return paramsMap;
	}

	public List<Market> getMarketByMarketType(Integer marketType) {
		return getDao().getMarketByMarketType(marketType);
	}

	public Market getMarketByCompanyId(Integer companyId) {
		return getDao().getMarketByCompanyId(companyId);
	}
	
	
	public Map<String, Object> getMarketComBox(Map<String, Object> paramsMap){
				
		List<Map<String, Object>> list=getDao().getMarketCombox(paramsMap);
		paramsMap.put("root", list);
		return paramsMap;
	}
	

	public Map<String,Object> selectLevel2Market4RepairStore(Integer marketType2Level) {
		List<Market> markets =  getMarketByMarketType(marketType2Level);
		SessionMessage sessionMessage = UserHolder.getCurrentSessionMessage();
		//该汽修厂的主市场
		/*Company company = (Company) companyDao.getById(sessionMessage.getCompanyId());
		Market market = (Market) getDao().getById(company.getMarketId());*/
		Market market = getMarketByCompanyId(sessionMessage.getCompanyId());
		Map<String,Object> map =new HashMap<String, Object>();
		map.put("markets", markets);
		map.put("marketName", market.getName());
		map.put("marketId", market.getId());
		return map;
	}

	public void setCompanyDao(ICompanyDao companyDao) {
		this.companyDao = companyDao;
	}
}
